package com.example.mobile2032021606168xmy0421homework;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class CarRViewAdapter extends RecyclerView.Adapter<CarRViewAdapter.ViewHolder> {
    List<Car>list;
    public CarRViewAdapter(List<Car>list){
        this.list=list;

    }
    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvName,tvText;


        public ViewHolder(@NonNull View itemView) {

            super(itemView);
            this.tvText=itemView.findViewById(R.id.tv_item_text);
            this.tvName=itemView.findViewById(R.id.tv_item_name);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_main_car,null);
        ViewHolder viewHolder =new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Car car =list.get(position);
        holder.tvName.setText(car.getNamme());
        holder.tvText.setText(car.getText());

    }

    @Override
    public int getItemCount() {

        return list.size();
    }
}
